import api from '../api'

export default {
  async register({ commit }, userData) {
    const response = await api.register(userData)
    commit('SET_TOKEN', response.token)
    commit('SET_USER', {
      id: response._id,
      username: response.username,
      email: response.email
    })
    return response
  },
  
  async login({ commit }, credentials) {
    const response = await api.login(credentials)
    commit('SET_TOKEN', response.token)
    commit('SET_USER', {
      id: response._id,
      username: response.username,
      email: response.email
    })
    return response
  },
  
  logout({ commit }) {
    commit('CLEAR_AUTH')
  },
  
  async submitEvaluation({ commit }, evaluationData) {
    return await api.submitEvaluation(evaluationData)
  },
  
  async checkOrderExists({ commit }, orderId) {
    return await api.checkOrderExists(orderId)
  },
  
  async getEvaluations({ commit }) {
    const evaluations = await api.getEvaluations()
    commit('SET_EVALUATIONS', evaluations)
    return evaluations
  },
  
  async sendEmail({ commit }, emailData) {
    return await api.sendEmail(emailData)
  }
}